#include <QApplication>
#include <QGraphicsView>
#include <QTimer>
#include "common.h"
#include "connection.h"
#include "loading.h"
#include "account.h"
#include "login.h"
#include "begin.h"
#include "param.h"
#include "music.h"
#include "pause.h"
#include "save.h"
#include "rank.h"
#include "statusvalue.h"

namespace Ui {
class Loading;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    StatusValue::status = Ready;
    Loading *loading = new Loading();
    loading->show();

    //创建和打开数据库链接
    if ( !createConnection())
        return 1;

    //设置字体点阵
    QFont font  = a.font();
    font.setPointSize(24);
    a.setFont(font);

    Login *login = new Login();
    login->hide();

    Account *account = new Account();
    account->hide();

    Begin *begin = new Begin();
    begin->hide();

    Param *param = new Param();
    param->hide();

    Music *music = new Music();
    music->hide();

    Rank *rank = new Rank();
    rank->hide();

    QObject::connect( login, SIGNAL(enterGame()), begin, SLOT(show()));
    QObject::connect( login, SIGNAL(createNewPlayer()), account, SLOT(show()));

    QObject::connect( account, SIGNAL(cancel()), login, SLOT(show()));
    QObject::connect( account, SIGNAL(enterGame()), login, SLOT(loginShow()));

    QObject::connect( begin, SIGNAL(enterParam()), param, SLOT(showParam()));
    QObject::connect( begin, SIGNAL(enterMusic()), music, SLOT(show()));
    QObject::connect( begin, SIGNAL(enterRank()), rank, SLOT(show()));

    QObject::connect( param, SIGNAL(enterBegin()), begin, SLOT(show()));

    QObject::connect( music, SIGNAL(enterBegin()), begin, SLOT(show()));

    QObject::connect( rank, SIGNAL(enterBegin()), begin, SLOT(show()));

    // 2秒单触发定时器
    QTimer *time = new QTimer;
    time->singleShot( 2000, loading, SIGNAL(over()));
    QObject::connect( loading, SIGNAL(over()), login, SLOT(show()));

    return a.exec();
}
